package io.renren.modules.finance.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.base.GenericServiceImpl;
import io.renren.modules.finance.dao.AgentMoneyTotalDao;
import io.renren.modules.finance.entity.UserMoneyTotal;
import io.renren.modules.finance.service.UserMoneyTotalService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 代理用户账户金额总表
 *
 * @author meishou
 * @date 2019-05-02 14:34:06
 */
@Service("userMoneyTotalService")
public class UserMoneyTotalServiceImpl extends GenericServiceImpl<AgentMoneyTotalDao, UserMoneyTotal> implements UserMoneyTotalService {

    /**
     * 查询代理账户金额
     *
     * @param userId
     * @return
     */
    public UserMoneyTotal getByUserId(Long userId) {
        UserMoneyTotal agentMoneyTotalEntity = baseMapper.selectOne(new QueryWrapper<UserMoneyTotal>().eq("user_id", userId));
        if (agentMoneyTotalEntity == null) {
            agentMoneyTotalEntity = new UserMoneyTotal();
            agentMoneyTotalEntity.setUserId(userId);
            agentMoneyTotalEntity.setBalanceIncome(BigDecimal.ZERO);
            agentMoneyTotalEntity.setTotalIncome(BigDecimal.ZERO);
            agentMoneyTotalEntity.setBalanceCoin(BigDecimal.ZERO);
            agentMoneyTotalEntity.setTotalCoin(BigDecimal.ZERO);
            agentMoneyTotalEntity.setWithdrawLockMoney(BigDecimal.ZERO);
            agentMoneyTotalEntity.setWithdrawTotal(BigDecimal.ZERO);
            agentMoneyTotalEntity.setModifyTime(DateUtil.date());
            agentMoneyTotalEntity.setCreateTime(DateUtil.date());
            baseMapper.insert(agentMoneyTotalEntity);
        }
        return agentMoneyTotalEntity;
    }




}
